package com.mochasoft.shangchm;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoadServlet extends HttpServlet {
    public LoadServlet() {
        super();
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setHeader("Cache-Control", "no-cache");
        response.setCharacterEncoding("utf-8");
		response.setContentType("text/xml;charset=UTF-8");
        System.out.println("服务器已经收到消息!");
        FileInputStream in = new FileInputStream("d:/test.xml");
        InputStreamReader read = new InputStreamReader (in,"utf-8");
        BufferedReader reader=new BufferedReader(read);
        StringBuilder  sb = new StringBuilder();
        String line ;
        while((line = reader.readLine())!=null){
        	sb.append(line);
        } 
        System.out.println(sb.toString());
        Writer writer = response.getWriter();
        writer.write(sb.toString()); //返回空字符串
        writer.flush();
        writer.close();
        
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);
    }
}
